def countSubstrings(s):
    ans = 0
    n = len(s)
    dp = [[False]*n for _ in range(n)]
    ans = 0
    for k in range(n):
        # i+k<n => i<n-k
        for i in range(n-k):
            j=i+k
            if k==0: 
                dp[i][j] = True
            elif k==1:
                dp[i][j] = s[i]==s[j]
            else:
                dp[i][j] = dp[i+1][j-1] and s[i]==s[j]
            if dp[i][j]: ans+=1
    return ans